<?php
require_once '../tools/SqlHelper.class.php';
// 该类是一个业务逻辑处理类,主要完成对admin表操作
class SpaceService {
	// 查询基本资料
	public function selectBaseData($user_id) {
		$sql = "select * from `personal_data_tb` where `user_id`='$user_id'";
		// 创建一个SqlHelper对象
		$sqlHelper = new SqlHelper ();
		$res = $sqlHelper->execute_dql2 ( $sql );
		// 关闭连接
		$sqlHelper->close_connect ();
		return $res;
	}
	// 更新基本资料
	public function updateBaseData($user_id, $ps_qq, $ps_blood_type, $ps_profession, $ps_marry_condition, $ps_birthplace, $ps_birthday, $ps_height, $ps_weight, $ps_education, $ps_monthly_income, $ps_apartment, $ps_is_house) {
		$sql = "UPDATE `personal_data_tb` SET `ps_qq`='$ps_qq', `ps_blood_type`='$ps_blood_type', 
				`ps_profession`='$ps_profession', `ps_marry_condition`='$ps_marry_condition', `ps_birthplace`='$ps_birthplace', 
				`ps_birthday`='$ps_birthday', `ps_height`='$ps_height', `ps_weight`='$ps_weight', 
				`ps_education`='$ps_education', `ps_monthly_income`='$ps_monthly_income', `ps_apartment`='$ps_apartment', 
				`ps_is_house`='$ps_is_house' WHERE `user_id`='$user_id'";
		// 创建一个SqlHelper对象
		$sqlHelper = new SqlHelper ();
		$res = $sqlHelper->execute_dql ( $sql );
		if (! $res) {
			echo "<script>alert('保存资料失败')</script>";
		} else {
			echo "<script>alert('保存资料成功')</script>";
		}
		// 资源
		mysql_free_result ( $res );
		// 关闭连接
		$sqlHelper->close_connect ();
		return true;
	}
	// 查询详细资料
	public function selectDetailData($user_id) {
		$sql = "select * from `detail_data_tb` where `user_id`='$user_id'";
		// 创建一个SqlHelper对象
		$sqlHelper = new SqlHelper ();
		$res = $sqlHelper->execute_dql ( $sql );
		/*
		 * $resNum = mysql_num_rows ( $res ); if ($resNum == 0) { $sql = "INSERT INTO `youyuan`.`detail_data_tb` (`user_id`) VALUES ('$user_id')"; $sqlHelper->execute_dql ( $sql ); }
		 */
		// 关闭连接
		$sqlHelper->close_connect ();
		return $res;
	}
	// 更新详细资料
	public function updateDetailData($user_id, $ps_qq, $ps_blood_type, $ps_profession, $ps_marry_condition, $ps_birthplace, $ps_birthday, $ps_height, $ps_weight, $ps_education, $ps_monthly_income, $ps_apartment, $ps_is_house) {
		$sql = "UPDATE `personal_data_tb` SET `ps_qq`='$ps_qq', `ps_blood_type`='$ps_blood_type',
		`ps_profession`='$ps_profession', `ps_marry_condition`='$ps_marry_condition', `ps_birthplace`='$ps_birthplace',
		`ps_birthday`='$ps_birthday', `ps_height`='$ps_height', `ps_weight`='$ps_weight',
		`ps_education`='$ps_education', `ps_monthly_income`='$ps_monthly_income', `ps_apartment`='$ps_apartment',
		`ps_is_house`='$ps_is_house' WHERE `user_id`='$user_id'";
		// 创建一个SqlHelper对象
		$sqlHelper = new SqlHelper ();
		$res = $sqlHelper->execute_dql ( $sql );
		if (! $res) {
			echo "<script>alert('保存资料失败')</script>";
		} else {
			echo "<script>alert('保存资料成功')</script>";
		}
		// 资源
		mysql_free_result ( $res );
		// 关闭连接
		$sqlHelper->close_connect ();
	}
	// 查询内心独白
	public function SoliloquyData($user_id) {
		$sql = "select dd_value from `detail_data_tb` where `user_id`='$user_id' and `dd_property`='soliloquy'";
		// 创建一个SqlHelper对象
		$sqlHelper = new SqlHelper ();
		$res = $sqlHelper->execute_dql ( $sql );
		/*
		 * $resNum = mysql_num_rows ( $res ); if ($resNum == 0) { $sql = "INSERT INTO `youyuan`.`detail_data_tb` (`user_id`) VALUES ('$user_id')"; $sqlHelper->execute_dql ( $sql ); }
		 */
		// 关闭连接
		$sqlHelper->close_connect ();
		return $res;
	}
	// 更新内心独白
	public function updateSoliloquyData($user_id, $soliloquy) {
		$sql = "INSERT INTO `detail_data_tb` (`user_id`, `dd_property`, `dd_value`) 
				VALUES ('xuf', 'd', 'd') ON DUPLICATE KEY UPDATE `dd_value` = '$soliloquy'";
		// 创建一个SqlHelper对象
		$sqlHelper = new SqlHelper ();
		$res = $sqlHelper->execute_dql ( $sql );
		if (! $res) {
			echo "<script>alert('保存资料失败')</script>";
		} else {
			echo "<script>alert('保存资料成功')</script>";
		}
		// 资源
		mysql_free_result ( $res );
		// 关闭连接
		$sqlHelper->close_connect ();
		return true;
	}
	// 查询上传头像
	public function selectIconData($user_id) {
		$sql = "select ps_Icon from `personal_data_tb` where `user_id`='$user_id'";
		// 创建一个SqlHelper对象
		$sqlHelper = new SqlHelper ();
		$res = $sqlHelper->execute_dql ( $sql );
		/*
		 * $resNum = mysql_num_rows ( $res ); if ($resNum == 0) { $sql = "INSERT INTO `youyuan`.`detail_data_tb` (`user_id`) VALUES ('$user_id')"; $sqlHelper->execute_dql ( $sql ); }
		 */
		// 关闭连接
		$sqlHelper->close_connect ();
		return $res;
	}
	// 更新上传头像
	public function updateIconoData($user_id, $ps_Icon) {
		$sql = "UPDATE `personal_data_tb` SET `ps_Icon`='$ps_Icon' WHERE `user_id`='$user_id'";
		// 创建一个SqlHelper对象
		$sqlHelper = new SqlHelper ();
		$res = $sqlHelper->execute_dql ( $sql );
		if (! $res) {
			echo "<script>alert('保存资料失败')</script>";
		} else {
			echo "<script>alert('保存资料成功')</script>";
		}
		// 资源
		mysql_free_result ( $res );
		// 关闭连接
		$sqlHelper->close_connect ();
		return true;
	}
	// 查询相册
	public function selectMyPhotoData($user_id) {
		$sql = $sql = "select * from `detail_data_tb` where `user_id`='$user_id' and `dd_property`='photo'";
		// 创建一个SqlHelper对象
		$sqlHelper = new SqlHelper ();
		$res = $sqlHelper->execute_dql ( $sql );
		/*
		 * $resNum = mysql_num_rows ( $res ); if ($resNum == 0) { $sql = "INSERT INTO `youyuan`.`detail_data_tb` (`user_id`) VALUES ('$user_id')"; $sqlHelper->execute_dql ( $sql ); }
		 */
		// 关闭连接
		$sqlHelper->close_connect ();
		return $res;
	}
	// 更新相册
	public function updateMyPhotoData($user_id, $ps_Icon) {
		/*
		 * $sql = "UPDATE `youyuan`.`personal_data_tb` SET `ps_Icon`='$ps_Icon' WHERE `user_id`='$user_id'"; // 创建一个SqlHelper对象 $sqlHelper = new SqlHelper (); $res = $sqlHelper->execute_dql ( $sql ); if (! $res) { echo "<script>alert('保存资料失败')</script>"; } else { echo "<script>alert('保存资料成功')</script>"; } // 资源 mysql_free_result ( $res ); // 关闭连接 $sqlHelper->close_connect (); return true;
		 */
	}
	// 查询征友条件
	public function selectPersonalConditionData($user_id) {
		$sql = "select * from `detail_data_tb` where `user_id`='$user_id'";
		// 创建一个SqlHelper对象
		$sqlHelper = new SqlHelper ();
		$res = $sqlHelper->execute_dql ( $sql );
		
		$resNum = mysql_num_rows ( $res );
		if ($resNum == 0) {
			$sql = "INSERT INTO `personals_condition_tb` (`user_id`) VALUES ('$user_id')";
			$sqlHelper->execute_dql ( $sql );
		}
		// 关闭连接
		$sqlHelper->close_connect ();
		return $res;
	}
	// 更新征友条件
	public function updatePersonalConditionData($user_id, $pc_address, $pc_age, $pc_height, $pc_education, $pc_income) {
		$sql = "UPDATE `personals_condition_tb` SET `pc_address`='$pc_address', `pc_age`='$pc_age', `pc_height`='$pc_height', 
		`pc_education`='$pc_education', `pc_income`='$pc_income' WHERE `user_id`='$user_id'";
		// 创建一个SqlHelper对象
		$sqlHelper = new SqlHelper ();
		$res = $sqlHelper->execute_dql ( $sql );
		if (! $res) {
			echo "<script>alert('保存资料失败')</script>";
		} else {
			echo "<script>alert('保存资料成功')</script>";
		}
		// 资源
		mysql_free_result ( $res );
		// 关闭连接
		$sqlHelper->close_connect ();
	}
}

?>